<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>轮播图点击切换</title>
  <style>
    * {
      box-sizing: border-box;
    }

    .slider {
      width: 560px;
      height: 660px;
      overflow: hidden;
    }

    .slider-wrapper {
      width: 100%;
      height: 560px;
    }

    .slider-wrapper img {
      width: 100%;
      height: 100%;
      display: block;
    }

    .slider-footer {
      height: 80px;
      background-color: rgb(100, 67, 68);
      padding: 12px 12px 0 12px;
      position: relative;
    }

    .slider-footer .toggle {
      position: absolute;
      display: flex;
      right: 0;
      top: 12px;
    }

    .slider-footer .toggle button {
      margin-right: 12px;
      width: 28px;
      height: 28px;
      border: none;
      appearance: none;
      color: #fff;
      background-color: rgba(255, 255, 255, 0.1);
      border-radius: 4px;
      cursor: pointer;
    }

    .slider-footer .toggle button:hover {
      background-color: rgba(255, 255, 255, 0.2);
    }

    .slider-footer p {
      margin: 0;
      color: #fff;
      font-size: 18px;
      margin-bottom: 10px;
    }

    .slider-indicator {
      margin: 0;
      padding: 0;
      display: flex;
      list-style: none;
      align-items: center;
    }

    .slider-indicator li {
      width: 8px;
      height: 8px;
      margin: 4px;
      border-radius: 50%;
      background: #fff;
      opacity: 0.4;
      cursor: pointer;
    }

    .slider-indicator li.active {
      width: 12px;
      height: 12px;
      opacity: 1;
    }
  </style>
</head>

<body>
  <div class="slider">
    <div class="slider-wrapper">
      <img src="../pic/1.jpg" alt="">
    </div>
    <div class="slider-footer">
      <p>王菲</p>
      <ul class="slider-indicator">
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
      </ul>
      <div class="toggle">
        <button class="prev">&lt;</button>
        <button class="next">&gt;</button>
      </div>
    </div>
  </div>
  <script>
    // 1.初始数据
    const sliderData = [
      { url: '../pic/1.jpg', title: '王菲', color: 'rgb(100, 67, 68)' },
      { url: '../pic/2.jpg', title: '陈奕迅', color: 'rgb(43, 35, 26)' },
      { url: '../pic/3.jpg', title: '李克勤', color: 'rgb(36, 31, 26)' },
      { url: '../pic/4.jpg', title: '张学友', color: 'rgb(139, 98, 66)' },
      { url: '../pic/5.jpg', title: '林俊杰', color: 'rgb(67, 90, 92)' },
      { url: '../pic/6.jpg', title: '周杰伦', color: 'rgb(166, 131, 143)' },
      { url: '../pic/7.jpg', title: '刘德华', color: 'rgb(53, 29, 25)' },
      { url: '../pic/8.jpg', title: '周柏豪', color: 'rgb(99, 72, 114)' },
    ]

    // 1.需要一个随机函数
    const random = parseInt(Math.random() * sliderData.length)
    // console.log(sliderData[random])
    // 2.把对应的数据渲染到标签里面
    // 2.1 获取图片
    const img = document.querySelector('.slider-wrapper img')
    // 2.2 修改图片路径    妙点-->对象.url
    img.src = sliderData[random].url
    img.title = sliderData[random].title
    // 3.把p里面的文字内容更换
    // 3.1 获取p
    const p = document.querySelector('.slider-footer p')
    // 3.2 修改p
    p.innerHTML = sliderData[random].title
    // 4.修改背景颜色
    const footer = document.querySelector('.slider-footer')
    footer.style.backgroundColor = sliderData[random].color
    // 5.小圆点
    const li = document.querySelector(`.slider-indicator li:nth-child(${random + 1})`)
    // console.log(li)
    // 让当前这个li添加active这个类
    li.classList.add('active')
  </script>
</body>

</html>